package com.thinksmart.qfilemanager.utils;

import android.webkit.MimeTypeMap;

import com.thinksmart.qfilemanager.R;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by F3060803 on 2017/6/23.
 */

public class Util {
    private  final static Map<String,Integer> MIMETypeToIconMap = new HashMap<String,Integer>();

    static {
        MIMETypeToIconMap.put("audio", R.mipmap.ic_audio);
        MIMETypeToIconMap.put("video", R.mipmap.ic_video);
        MIMETypeToIconMap.put("image", R.mipmap.ic_image);
        MIMETypeToIconMap.put("text", R.mipmap.ic_doc);
    }

    public static String getMIMEType(String fileName) {
        String type = "*/*";
        MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();

        if (fileName != null) {
            int index = fileName.lastIndexOf('.');

            if (index > 0) {
                String suffix = fileName.substring(index+1).toLowerCase();
                if (suffix != null && !suffix.isEmpty() && mimeTypeMap != null) {
                    type = mimeTypeMap.getMimeTypeFromExtension(suffix);
                }
            }
        }
        return type;
    }

    public static int getIconFromMIMEType(String mimeType) {
        int resId = R.mipmap.ic_file;



        return resId;
    }
}
